import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class CustomerMenuFrame extends JFrame {
    public CustomerMenuFrame() {
        setTitle("客户菜单");
        setSize(400, 300);
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
        setLocationRelativeTo(null);

        JPanel panel = new JPanel(new GridBagLayout());
        add(panel);

        GridBagConstraints gbc = new GridBagConstraints();
        gbc.insets = new Insets(5, 5, 5, 5);
        gbc.anchor = GridBagConstraints.CENTER;
        gbc.fill = GridBagConstraints.HORIZONTAL;

        JLabel menuLabel = new JLabel("欢迎来到客户菜单!");
        gbc.gridx = 0;
        gbc.gridy = 0;
        panel.add(menuLabel, gbc);

        JButton changeCustomerPasswordButton = new JButton("修改密码");
        gbc.gridy = 1;
        panel.add(changeCustomerPasswordButton, gbc);

        JButton shoppingButton = new JButton("购物");
        gbc.gridy = 2;
        panel.add(shoppingButton, gbc);

        JButton logoutButton = new JButton("退出登录");
        gbc.gridy = 3;
        panel.add(logoutButton, gbc);

        // 按钮事件监听器
        changeCustomerPasswordButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                // 打开修改密码界面
                ChangeCustomerPasswordFrame changeCustomerPasswordFrame = new ChangeCustomerPasswordFrame();
                changeCustomerPasswordFrame.setVisible(true);
            }
        });

        shoppingButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                dispose();
                ShoppingFrame shoppingFrame = new ShoppingFrame();
                shoppingFrame.setVisible(true);
            }
        });

        logoutButton.addActionListener(e -> {
            dispose();
            LoginFrame loginFrame = new LoginFrame();  // 重新打开登录界面
            loginFrame.setVisible(true);
        });
    }
}
